<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>航运物流 - 承运商中心</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #3498db 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        /* 海洋波浪背景动画 */
        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: 
                radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(120, 119, 198, 0.2) 0%, transparent 50%);
            animation: oceanWave 15s ease-in-out infinite;
        }

        @keyframes oceanWave {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            33% { transform: translateY(-10px) rotate(1deg); }
            66% { transform: translateY(5px) rotate(-1deg); }
        }

        .container {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border-radius: 25px;
            box-shadow: 
                0 25px 50px rgba(0, 0, 0, 0.2),
                0 0 0 1px rgba(255, 255, 255, 0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.4);
            padding: 40px 50px 60px;
            width: 100%;
            max-width: 480px;
            position: relative;
            z-index: 1;
            animation: slideIn 0.8s ease-out;
            border: 1px solid rgba(255, 255, 255, 0.2);
            min-height: 650px;
            display: flex;
            flex-direction: column;
        }

        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateY(30px) scale(0.95);
            }
            to {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

        .logo {
            text-align: center;
            margin-bottom: 35px;
        }

        .logo h1 {
            color: #2c3e50;
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #3498db, #1e3c72, #2980b9);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .logo p {
            color: #7f8c8d;
            font-size: 15px;
            font-weight: 400;
            margin-bottom: 20px;
        }

        /* 模式切换按钮 */
        .mode-switcher {
            display: flex;
            background: rgba(236, 240, 241, 0.8);
            border-radius: 15px;
            padding: 5px;
            margin-bottom: 30px;
            border: 1px solid rgba(255, 255, 255, 0.5);
        }

        .mode-btn {
            flex: 1;
            padding: 12px 20px;
            border: none;
            border-radius: 12px;
            background: transparent;
            color: #7f8c8d;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
        }

        .mode-btn.active {
            background: linear-gradient(135deg, #3498db, #2980b9);
            color: white;
            box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
        }

        .mode-btn:hover:not(.active) {
            background: rgba(255, 255, 255, 0.6);
            color: #34495e;
        }

        .form-container {
            position: relative;
            overflow: hidden;
            min-height: 400px;
            flex: 1;
        }

        .form-section {
            position: absolute;
            width: 100%;
            transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .form-section.hidden {
            opacity: 0;
            transform: translateX(100%);
            pointer-events: none;
        }

        .form-section.show {
            opacity: 1;
            transform: translateX(0);
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 10px;
            color: #34495e;
            font-weight: 600;
            font-size: 14px;
            transition: color 0.3s ease;
        }

        .form-group input {
            width: 100%;
            padding: 16px 20px;
            border: 2px solid #ecf0f1;
            border-radius: 15px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.9);
            color: #2c3e50;
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .form-group input:focus {
            outline: none;
            border-color: #3498db;
            background: rgba(255, 255, 255, 1);
            box-shadow: 
                0 0 0 4px rgba(52, 152, 219, 0.1),
                inset 0 2px 4px rgba(0, 0, 0, 0.05);
            transform: translateY(-2px);
        }

        .form-group input::placeholder {
            color: #95a5a6;
            font-size: 14px;
        }

        .form-group .icon {
            position: absolute;
            right: 18px;
            top: 50%;
            transform: translateY(-50%);
            color: #3498db;
            font-size: 20px;
            transition: color 0.3s ease;
            opacity: 1;
        }

        .submit-btn {
            width: 100%;
            padding: 16px;
            background: linear-gradient(135deg, #3498db, #2980b9, #1e3c72);
            color: white;
            border: none;
            border-radius: 15px;
            font-size: 17px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 15px;
            position: relative;
            overflow: hidden;
            box-shadow: 0 8px 20px rgba(52, 152, 219, 0.3);
        }

        .submit-btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 12px 30px rgba(52, 152, 219, 0.4);
        }

        .submit-btn:active {
            transform: translateY(-1px);
        }

        .submit-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
            transition: left 0.6s;
        }

        .submit-btn:hover::before {
            left: 100%;
        }

        .submit-btn.loading {
            pointer-events: none;
            opacity: 0.8;
        }

        .submit-btn.loading::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 20px;
            height: 20px;
            margin: -10px 0 0 -10px;
            border: 2px solid transparent;
            border-top: 2px solid white;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .message {
            padding: 15px 20px;
            border-radius: 12px;
            margin-bottom: 25px;
            font-size: 14px;
            font-weight: 500;
            animation: fadeIn 0.3s ease;
            display: none;
            backdrop-filter: blur(10px);
        }

        .message.success {
            background: rgba(46, 204, 113, 0.15);
            color: #27ae60;
            border: 1px solid rgba(46, 204, 113, 0.3);
        }

        .message.error {
            background: rgba(231, 76, 60, 0.15);
            color: #c0392b;
            border: 1px solid rgba(231, 76, 60, 0.3);
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .switch-link {
            text-align: center;
            margin-top: 25px;
            color: #7f8c8d;
            font-size: 15px;
        }

        .switch-link a {
            color: #3498db;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
            border-bottom: 1px solid transparent;
        }

        .switch-link a:hover {
            color: #2980b9;
            border-bottom-color: #3498db;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .container {
                margin: 20px;
                padding: 40px 25px;
            }
            
            .logo h1 {
                font-size: 28px;
            }
        }

        /* 航运图标 */
        .shipping-icon {
            display: inline-block;
            margin-right: 10px;
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
            animation: none;
            transform: none;
            opacity: 1;
            background: transparent;
        }

        /* 额外登录字段 */
        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            font-size: 14px;
        }

        .remember-me {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .remember-me input[type="checkbox"] {
            width: auto;
            margin: 0;
        }

        .forgot-password {
            color: #3498db;
            text-decoration: none;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .forgot-password:hover {
            color: #2980b9;
            text-decoration: underline;
        }

        /* 用户/承运商切换链接 */
        .role-switch {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid rgba(236, 240, 241, 0.8);
            color: #7f8c8d;
            font-size: 14px;
        }

        .role-switch a {
            color: #e74c3c;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .role-switch a:hover {
            color: #c0392b;
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">
            <h1><span class="shipping-icon">🚚</span>承运商中心</h1>
            <p>专业航运管理平台</p>
        </div>

        <!-- 模式切换按钮 -->
        <div class="mode-switcher">
            <button class="mode-btn active" id="loginBtn" onclick="switchMode('login')">登录</button>
            <button class="mode-btn" id="registerBtn" onclick="switchMode('register')">注册</button>
        </div>

        <div id="message" class="message"></div>

        <div class="form-container">
            <!-- 登录表单 -->
            <div id="loginForm" class="form-section show">
                <form onsubmit="handleLogin(event)">
                    <div class="form-group">
                        <label for="loginId">承运商ID</label>
                        <input type="number" id="loginId" name="id" placeholder="请输入承运商ID" required>
                        <span class="icon">👤</span>
                    </div>

                    <div class="form-group">
                        <label for="loginPasswd">密码</label>
                        <input type="password" id="loginPasswd" name="passwd" placeholder="请输入密码" required>
                        <span class="icon">🔒</span>
                    </div>

                    <div class="remember-forgot">
                        <div class="remember-me">
                            <input type="checkbox" id="remember" name="remember">
                            <label for="remember">记住我</label>
                        </div>
                        <a href="#" class="forgot-password" onclick="showForgotPassword()">忘记密码？</a>
                    </div>

                    <button type="submit" class="submit-btn" id="loginSubmitBtn">
                        登录
                    </button>
                </form>

                <div class="switch-link">
                    还没有账户？<a href="#" onclick="switchMode('register')">立即注册</a>
                </div>
            </div>

            <!-- 注册表单 -->
            <div id="registerForm" class="form-section hidden">
                <form onsubmit="handleRegister(event)">
                    <div class="form-group">
                        <label for="regName">承运商名称</label>
                        <input type="text" id="regName" name="name" placeholder="请输入承运商名称" required>
                        <span class="icon">🚚</span>
                    </div>

                    <div class="form-group">
                        <label for="regInfo">承运商信息</label>
                        <input type="text" id="regInfo" name="info" placeholder="请输入承运商信息" required>
                        <span class="icon">📝</span>
                    </div>

                    <div class="form-group">
                        <label for="regPasswd">密码</label>
                        <input type="password" id="regPasswd" name="passwd" placeholder="请输入密码" required>
                        <span class="icon">🔒</span>
                    </div>

                    <button type="submit" class="submit-btn" id="regSubmitBtn">
                        注册账户
                    </button>
                </form>

                <div class="switch-link">
                    已有账户？<a href="#" onclick="switchMode('login')">立即登录</a>
                </div>
            </div>
        </div>

        <!-- 用户/承运商切换 -->
        <div class="role-switch">
            普通用户请点击 <a href="user.html">这里</a> 登录
        </div>
    </div>

    <script>
        let currentMode = 'login';

        // 切换模式
        function switchMode(mode) {
            if (currentMode === mode) return;
            
            currentMode = mode;
            
            // 更新按钮状态
            document.getElementById('loginBtn').classList.toggle('active', mode === 'login');
            document.getElementById('registerBtn').classList.toggle('active', mode === 'register');
            
            // 切换表单
            const loginForm = document.getElementById('loginForm');
            const registerForm = document.getElementById('registerForm');
            
            if (mode === 'login') {
                loginForm.classList.remove('hidden');
                loginForm.classList.add('show');
                registerForm.classList.remove('show');
                registerForm.classList.add('hidden');
            } else {
                registerForm.classList.remove('hidden');
                registerForm.classList.add('show');
                loginForm.classList.remove('show');
                loginForm.classList.add('hidden');
            }
            
            // 隐藏消息
            hideMessage();
        }

        // 处理登录
        async function handleLogin(event) {
            event.preventDefault();
            
            const id = document.getElementById('loginId').value.trim();
            const passwd = document.getElementById('loginPasswd').value;
            const submitBtn = document.getElementById('loginSubmitBtn');

            if (!id || !passwd) {
                showMessage('请填写所有必填字段', 'error');
                return;
            }

            // 显示加载状态
            submitBtn.classList.add('loading');
            submitBtn.textContent = '登录中...';

            try {
                const response = await fetch('http://172.21.136.104:8080/carrier/check', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: new URLSearchParams({
                        id: id,
                        passwd: passwd
                    })
                });

                const result = await response.json();

                if (result.code == '0' && result.data) {
                    showMessage('登录成功！正在跳转...', 'success');
                    setTimeout(() => {
                        // 登录成功后的跳转逻辑
                        console.log('登录成功，承运商ID:', id);
                        window.location.href = 'carrier-dashboard.html?id=' + id;
                    }, 1500);
                } else {
                    showMessage(result.message || '登录失败，用户名或密码错误', 'error');
                }
            } catch (error) {
                console.error('登录错误:', error);
                showMessage('网络错误，请检查连接后重试', 'error');
            } finally {
                submitBtn.classList.remove('loading');
                submitBtn.textContent = '登录';
            }
        }

        // 处理注册
        async function handleRegister(event) {
            event.preventDefault();
            
            const name = document.getElementById('regName').value.trim();
            const info = document.getElementById('regInfo').value.trim();
            const passwd = document.getElementById('regPasswd').value;
            const submitBtn = document.getElementById('regSubmitBtn');

            if (!name || !info || !passwd) {
                showMessage('请填写所有必填字段', 'error');
                return;
            }

            if (name.length < 3) {
                showMessage('承运商名称至少需要3个字符', 'error');
                return;
            }

            if (info.length < 5) {
                showMessage('承运商信息至少需要5个字符', 'error');
                return;
            }

            if (passwd.length < 6) {
                showMessage('密码至少需要6个字符', 'error');
                return;
            }

            // 显示加载状态
            submitBtn.classList.add('loading');
            submitBtn.textContent = '注册中...';

            try {
                const response = await fetch('http://172.21.136.104:8080/carrier/add', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: new URLSearchParams({
                        name: name,
                        info: info,
                        passwd: passwd
                    })
                });

                const result = await response.json();

                if (result.code == '0') {
                    showMessage('注册成功！正在跳转到登录页面...', 'success');
                    setTimeout(() => {
                        switchMode('login');
                        // 清空注册表单
                        document.getElementById('regName').value = '';
                        document.getElementById('regInfo').value = '';
                        document.getElementById('regPasswd').value = '';
                    }, 2000);
                } else {
                    showMessage(result.message || '注册失败，请重试', 'error');
                }
            } catch (error) {
                console.error('注册错误:', error);
                showMessage('网络错误，请检查连接后重试', 'error');
            } finally {
                submitBtn.classList.remove('loading');
                submitBtn.textContent = '注册账户';
            }
        }

        // 显示消息
        function showMessage(text, type) {
            const message = document.getElementById('message');
            message.textContent = text;
            message.className = `message ${type}`;
            message.style.display = 'block';
            
            // 3秒后自动隐藏
            setTimeout(() => {
                hideMessage();
            }, 3000);
        }

        // 隐藏消息
        function hideMessage() {
            const message = document.getElementById('message');
            message.style.display = 'none';
        }

        // 忘记密码
        function showForgotPassword() {
            showMessage('请联系管理员重置密码', 'error');
        }

        // 输入框焦点效果
        document.querySelectorAll('input').forEach(input => {
            input.addEventListener('focus', function() {
                this.parentElement.style.transform = 'scale(1.02)';
            });
            
            input.addEventListener('blur', function() {
                this.parentElement.style.transform = 'scale(1)';
            });
        });

        // 记住我功能（本地存储）
        window.addEventListener('DOMContentLoaded', function() {
            const savedId = localStorage.getItem('savedCarrierId');
            if (savedId) {
                document.getElementById('loginId').value = savedId;
                document.getElementById('remember').checked = true;
            }
        });

        // 保存承运商ID
        document.getElementById('remember').addEventListener('change', function() {
            if (this.checked) {
                const carrierId = document.getElementById('loginId').value;
                if (carrierId) {
                    localStorage.setItem('savedCarrierId', carrierId);
                }
            } else {
                localStorage.removeItem('savedCarrierId');
            }
        });
    </script>
</body>
</html>